package com.example.myapplication3.document.bean;

import android.net.Uri;

public class DocumentItem {
    private long id;
    private String name;
    private String path;
    private Uri uri;
    private long size;
    private long dateAdded;
    private long dateModified;
    private String mimeType;
    private String extension;

    public DocumentItem(long id, String name, String path, Uri uri, long size,
                        long dateAdded, long dateModified, String mimeType, String extension) {
        this.id = id;
        this.name = name;
        this.path = path;
        this.uri = uri;
        this.size = size;
        this.dateAdded = dateAdded;
        this.dateModified = dateModified;
        this.mimeType = mimeType;
        this.extension = extension;
    }

    // Getters
    public long getId() { return id; }
    public String getName() { return name; }
    public String getPath() { return path; }
    public Uri getUri() { return uri; }
    public long getSize() { return size; }
    public long getDateAdded() { return dateAdded; }
    public long getDateModified() { return dateModified; }
    public String getMimeType() { return mimeType; }
    public String getExtension() { return extension; }

    public String getFormattedSize() {
        if (size <= 0) return "0 B";
        final String[] units = new String[]{"B", "KB", "MB", "GB", "TB"};
        int digitGroups = (int) (Math.log10(size) / Math.log10(1024));
        return String.format("%.1f %s", size / Math.pow(1024, digitGroups), units[digitGroups]);
    }

    public String getFormattedDate() {
        return android.text.format.DateFormat.format("yyyy-MM-dd HH:mm", dateAdded * 1000).toString();
    }

    public String getFileType() {
        if (mimeType == null) return "Unknown";
        if (mimeType.startsWith("application/pdf")) return "PDF";
        if (mimeType.startsWith("application/msword")) return "Word";
        if (mimeType.startsWith("application/vnd.ms-excel")) return "Excel";
        if (mimeType.startsWith("application/vnd.ms-powerpoint")) return "PowerPoint";
        if (mimeType.startsWith("text/")) return "Text";
        return "Document";
    }
}